package com.smileus.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class EnvProperties {
	private static Properties prop;

	public static void init() {
		prop = new Properties();
		InputStream in = EnvProperties.class.getResourceAsStream("/Env.properties");
		try {
			prop.load(in);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
				throw new RuntimeException(" stream close fail!");
			}
		}
	}

	public static String getProperty(String key) {
		if (prop == null) {
			init();
		}

		String value = prop.getProperty(key);
		if (value == null || "".equals(value)) {
			throw new RuntimeException(key + "在配置文件Env.properties中没有匹配的值!");
		}

		return value;
	}
}
